﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace System
{
    /// <summary>
    /// 扩展方法使锁定更容易。
    /// </summary>
    public static class LockExtension
    {
        /// <summary>
        /// 通过锁定给定的源对象来执行给定的操作。
        /// </summary>
        /// <typeparam name="T">要锁定的对象类型</typeparam>
        /// <param name="source">要锁定的对象来源</param>
        /// <param name="action">行为</param>
        public static void Locking<T>(this T source, Action<T> action) where T : class
        {
            lock (source)
            {
                action(source);
            }
        }
    }
}
